# -*- coding: utf-8 -*-
"""
Spyder 编辑器

比较两个文件内的所有文件
"""


import os

def compare_folders(folder1, folder2):
    files_set1 = set()
    files_set2 = set()

    # 获取文件夹1中的所有文件路径
    for foldername, subfolders, filenames in os.walk(folder1):
        for filename in filenames:
            files_set1.add(os.path.relpath(os.path.join(foldername, filename), folder1))

    # 获取文件夹2中的所有文件路径
    for foldername, subfolders, filenames in os.walk(folder2):
        for filename in filenames:
            files_set2.add(os.path.relpath(os.path.join(foldername, filename), folder2))

    # 找到文件夹1中存在但文件夹2中不存在的文件
    diff_files1 = files_set1 - files_set2

    # 找到文件夹2中存在但文件夹1中不存在的文件
    diff_files2 = files_set2 - files_set1

    return diff_files1, diff_files2

folder1 = 'Z:/virtual_share/calibre_lib'
folder2 = 'Z:/virtual_share/calibre_lib_2'

diff_files1, diff_files2 = compare_folders(folder1, folder2)

# 增加格式看起来清晰
print("Files in folder1 but not in folder2:")
for i in diff_files1:
    print(i)
print()
print("Files in folder2 but not in folder1:")
for i in diff_files2:
    print(i)


